require(['common', 'jQuery', "coAjax"], function(jSouper, $, coAjax) {
	var goodsChoseMap = {
		1: "G_8872729514b43e60679",
		2: "G_245f5ce714b43e68d15",
		3: "G_5a8fa5b214b20d5eb1c"
	};
	if (location.hostname === "dev.dotnar.com") {
		var goodsChoseMap = {
			1: "G_c4b1acbb14b43b28e86",
			2: "G_bf619b5614b43b30757",
			3: "G_3de9cd4b14b43b3749e"
		};
	}
	var subjectChoseMap = {
		1: "【点纳微站】续费1个月",
		2: "【点纳微站】续费1季度（3个月）",
		1: "【点纳微站】续费1年"
	};
	App.set('$Cache.chose', 3);
	App.set("$Event.chosePay", function() {
		App.set("$Cache.chose", $(this).attr('data'));
	});
	App.set("$Event.busBuy", function() {
		var payWindow = window.open();
		payWindow.document.write("<h2>跳转中，请稍等……</h2>");
		//商家使用消费者身份登录
		coAjax.post(appConfig.user.sign_in_url + "?from_bus=true", function() {
			var chose_index = App.get("$Cache.chose")
			var goods_id = goodsChoseMap[chose_index];
			//进行下单
			coAjax.post(appConfig.user.goods_make_ach, {
				goods_id: goods_id,
				num: 1,
				pay_method: appConfig.PAY_METHOD["担保交易"]
			}, function(result) {
				var ach = result.result;
				var ach_id = ach._id;
				//直接确认订单
				coAjax.put(appConfig.user.ach_lock + ach_id, function(result) {
					var ach = result.result;
					//生成表单
					coAjax.post(appConfig.alipay.create_direct_pay_by_user_form_ach_id + ach_id, {
						WIDsubject: subjectChoseMap[chose_index],
						type:"url"
					}, function(result) {
						var toPayUrl = result.toString;
						payWindow.location.href = toPayUrl;
					});
				});
			});
		});
	});
});